﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TinySkill
{




    //用来在技能编辑器中显示中文字段名称
    public class EditorNameAttribute : Attribute
    {
        string _name;

        public EditorNameAttribute(string name)
        {
            this._name = name;
        }

        public string EditorName
        {
            get { return this._name; }
            set { this._name = value; }
        }
    }

    //用来在编辑器中显示中文字段描述
    public class EditorDescriptionAttribute : Attribute
    {
        string _name;

        public EditorDescriptionAttribute(string name)
        {
            this._name = name;
        }

        public string EditorDescription
        {
            get { return this._name; }
            set { this._name = value; }
        }
    }

    //让编辑器忽略此字段
    public class EditorIgnoreAttribute : Attribute
    {
    }

    //将字段标记为可预加载
    public class PreloadAttribute : Attribute
    {
        public enum EResType
        {
            GameObject,
            AudioClip,
            Texture,
            Buff,
            Sound
        }
        EResType _type;
        public PreloadAttribute(EResType e) { _type = e; }
        public EResType resType { get { return _type; } }
    }


    [ProtoBuf.ProtoContract]
    public class config_skill
    {
        [ProtoBuf.ProtoMember(1)]
        public int id;
        [ProtoBuf.ProtoMember(2), EditorName("名称")]
        public string name;
        [ProtoBuf.ProtoMember(3), EditorName("朝向目标"), System.ComponentModel.DefaultValue(true)]
        public bool face_target = true;

        [ProtoBuf.ProtoMember(8), EditorName("帧数")]
        public int frame_count;

        [ProtoBuf.ProtoMember(9)]
        public float cd;

        [ProtoBuf.ProtoMember(10), EditorIgnore]
        public config_skill_frame[] frames = new config_skill_frame[0];

        [ProtoBuf.ProtoMember(11)]
        public float pre_cd;

        [ProtoBuf.ProtoMember(12), EditorName("技能描述")]
        public string describe;

        [ProtoBuf.ProtoMember(13), EditorName("技能图标")]
        public string icon;

        [ProtoBuf.ProtoMember(14), EditorName("技能名称")]
        public string skillName;

        //依据播放顺序排序关键帧。
        public void Sorts()
        {
            if (frames == null || frames.Length <= 1)
                return;

            List<config_skill_frame> frame_list = new List<config_skill_frame>();
            frame_list.AddRange(frames);
            frame_list.Sort((a, b) =>
            {
                if (a.frame_index < b.frame_index)
                    return -1;
                else if (a.frame_index == b.frame_index)
                    return 0;
                return 1;
            });
            frames = frame_list.ToArray();
        }
    }

}